package com.jumi.microservice.controller.api;

import com.jumi.microservice.common.base.BaseController;
import com.jumi.microservice.common.base.dto.ResponseResult;

import com.jumi.microservice.common.page.TableDataInfo;
import com.jumi.microservice.dto.comment.api.*;
import com.jumi.microservice.service.api.CommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author Scw
 * @Date 2020-08-04 17:55
 */
@Api(tags = {"前台商品评论相关接口"})
@RestController
@RequestMapping("/api/comment")
public class CommentController extends BaseController {
    @Resource
    private CommentService commentService;

    @PostMapping("/addComment")
    @ApiOperation("评论添加")
    public ResponseResult<Boolean> addComment(CommentApiAddRequest commentApiAddRequest) {
        ResponseResult<Boolean> result = new ResponseResult<>();
        //获取当前用户ID
        commentApiAddRequest.setUid(getApiUserId().longValue());
        commentApiAddRequest.setUserName(getApiUserName());
        //commentApiAddRequest.setUid(10119L);
        result.setData(commentService.addComment(commentApiAddRequest));
        return result;
    }

    @GetMapping("/commentList")
    @ApiOperation("评论列表")
    TableDataInfo<CommentApiListResponse> commentList(CommentApiListRequest commentApiListRequest) {
        //获取当前用户ID
        commentApiListRequest.setUid(getApiUserId().longValue());
        return commentService.commentsApiList(commentApiListRequest);
    }

    @GetMapping("/commentListSpu")
    @ApiOperation("spu商品评论列表")
    TableDataInfo<CommentApiListResponse> commentListSpu(CommentSpuRequest commentSpuRequest) {
        return commentService.commentListSpuList(commentSpuRequest);
    }


    @PostMapping("/addBatchComment")
    @ApiOperation("评论批量添加")
    public ResponseResult<Boolean> addBatchComment(@RequestBody CommentApiAddBatchRequest commentApiAddBatchRequest) {
        ResponseResult<Boolean> result = new ResponseResult<>();
        //获取当前用户ID
        commentApiAddBatchRequest.setUid(getApiUserId().longValue());
        commentApiAddBatchRequest.setUserName(getApiUserName());

        result.setData(commentService.addBatchComment(commentApiAddBatchRequest));
        return result;
    }

    @GetMapping("/commentNewOne")
    @ApiOperation("最新一条评论")
    public CommentApiOneResponse commentNewOne(CommentApiOneRequest commentApiOneRequest) {
        return commentService.commentNewOned(commentApiOneRequest);
    }

    @GetMapping("/commentListUid")
    @ApiOperation("用户uid查询评论列表orderid")
    TableDataInfo<CommentApiUidResponse> commentListUid(CommentApiUidRequest commentApiUidRequest) {
        return commentService.commentListUid(commentApiUidRequest);
    }
    @GetMapping("/commentGidNum")
    @ApiOperation("一级搜索商品评价顶部评论数量")
    public ResponseResult<CommentSpuGidResponse> commentGidNum(CommentSpuGidRequest commentSpuGidRequest) {
        return success(commentService.commentGidNum(commentSpuGidRequest));
    }

    @GetMapping("/commentGidTwoNum")
    @ApiOperation("二级搜索商品评价图片回头客数量")
    public ResponseResult<CommentSpuImageNumResponse> commentGidTwoNum(CommentSpuImageNumRequest commentSpuImageNumRequest) {
        return success(commentService.commentGidTwoNum(commentSpuImageNumRequest));
    }

}

